// pages/loupan/youhuilist.js
var app = getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: { 
		limit: 5,
    searchlimit:5,
		youhui:'',
		searchvalue:'',
    searchbnt:false
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		this.list(6)
	},
	list(limit) {
		var that = this;
		var setid = app.globalData.cityCode; 
		var url = "get_yh_more_list/site_id/" + setid+"/limit/" + limit + "";
	
		app.core('get', url, '', (res => {
			console.log(res);
			that.setData({
				youhui: res.data,
				limit: limit + 5
			});
		}))
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */

	searchlist(e){
		this.setData({
			searchvalue: e.detail.value
		})
	},

	searchdesc() {

		var that = this;
	
		var searchvalue = that.data.searchvalue;
		if (searchvalue == '') {
			wx.showToast({
				title: '请输入内容',
				duration: 1000,
				icon: 'none'
			})
		} else {
      that.searchlistsss(searchvalue,6)
		}

	},
 
  searchlistsss(searchvalue,limit){
    wx.showLoading({
      title: '加载中',
    })
      var that = this;
    var setid = app.globalData.cityCode;
		app.core('get', 'get_yh_more_list/site_id/' + setid + '/limit/'+limit+'', {
			keywords: searchvalue
      }, (res) => {
        console.log(res)
        if(res.data.length != 0){
					that.setData({
						searchbnt: true,
						searchlimit: limit + 5,
						youhui: res.data
					})
				}else{
					wx.showToast({
						title: '暂无搜索内容',
						duration: 1000,
						icon: 'none'
					})
				}
      
        wx.hideLoading()
      })
    },

	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		var that = this;
    var type = that.data.searchbnt;
    var searchlimit = that.data.searchlimit;

    if(type == false){
      console.log(this.data.limit);

      var limit = that.data.limit;
      var type = that.data.type;
      that.list(limit)
      console.log(111)
    }else{
      console.log(searchlimit)
    
      var searchvalue = that.data.searchvalue;
      that.searchlistsss(searchvalue, searchlimit);
      console.log(222)
    }
  
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})